#include<stdlib.h>
#include "recoProxy_vad.h"
#include"vadInst.h"
#include "webrtcVadInst.h"
#include "../../api/api.h"

vadCbUtil* createVadCbUtil(vadCallBackFunc vadCbFunc, vadCloseCb vadCbCloseFunc, vadCbUpdateTime vadCbUpdateTimeFunc, CBINST vadCbInst)
{
	vadCbUtil * utilInst = static_cast<vadCbUtil *>(malloc(sizeof(vadCbUtil)));
	utilInst->_vadCbFunc = vadCbFunc;
	utilInst->_vadCbCloseFunc = vadCbCloseFunc;
	utilInst->_vadCbUpdateTimeFunc = vadCbUpdateTimeFunc;
	utilInst->_vadCbInst = vadCbInst;
	return utilInst;
}
void releaseVadCbUtil(vadCbUtil* pUtil)
{
	free(pUtil);
}
void* recoProxyCreateVad(void* pVadOptions, int iType,vadCbUtil* pCbUtil)
{
	vadOptions* pVadOption = static_cast<vadOptions*>(pVadOptions);
	webrtcVadInst* pInst = new webrtcVadInst(pVadOption,iType,pCbUtil);
	return pInst;
	
}
void recoProxyInitVad(void* pVadHdl)
{
	vadInst* pInst = static_cast<vadInst*> (pVadHdl);
	if(pInst)
		pInst->init();
}

void recoProxyVadFeedData(void* pVadHdl,char* pData,int iLen)
{
	vadInst* pInst = static_cast<vadInst*> (pVadHdl);
	if(pInst)
		pInst->writeBuffer(pData,iLen);
}
void recoProxyCloseVad(void* pVadHdl)
{
	vadInst* pInst = static_cast<vadInst*> (pVadHdl);
	if(pInst)
	{
		pInst->close();
		delete pInst;
	}
}
